﻿using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Facebook.Rest;
using Facebook.Session;
using Facebook.Schema;
using System.Configuration;


public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (CurrentSession.IsConnected())
        {
            //Load data for authanticated user
            //LoadData();
            Response.Redirect("~/PostListingInProcess.aspx?ListingId=" + Request.QueryString["ListingId"].ToString());
        }   
    }

    /// <summary>
    /// Store friend Id's fetched from REST
    /// </summary>
    public List<long> FriendIDs
    {
        get
        {
            if (Session["FB_FRIENDS_FRIENDSIDS"] != null)
                return (List<long>)Session["FB_FRIENDS_FRIENDSIDS"];
            else
                return new List<long>();
        }
        set
        {
            Session["FB_FRIENDS_FRIENDSIDS"] = value;
        }
    }

    /// <summary>
    /// Store friend's fetched from REST
    /// </summary>
    public IList<user> Friends
    {
        get
        {
            if (Session["FB_FRIENDS_FRIENDS"] != null)
                return (IList<user>)Session["FB_FRIENDS_FRIENDS"];
            else
                return null;
        }
        set
        {
            Session["FB_FRIENDS_FRIENDS"] = value;
        }
    }

    /// <summary>
    /// Get the current authanticated facebook session
    /// </summary>
    public ConnectSession CurrentSession
    {
        get
        {
            ConnectSession connectSession = new ConnectSession(
               ConnectAuthentication.ApiKey,
               ConnectAuthentication.SecretKey);

            return connectSession;
        }
    }

    
    //private void LoadData()
    //{
    //    Api api = new Api(CurrentSession);

    //    Facebook.Schema.user user = api.Users.GetInfo();

    //    string userId = user.uid.ToString();
    //    string userImage=user.pic_big;
    //    string fullName = user.first_name + " " + user.last_name;
        
    //    DataTable dtProfileAgentId=new DataTable();

    //    dtProfileAgentId=BuddyAgentDAL.SetProfileAgentInformation(fullName, userImage, userId, Convert.ToInt32(Request.QueryString["ListingId"]));
      
    //    List<long> myFrndId = (List<long>)api.Friends.Get();
    //    int agentId=Convert.ToInt32(dtProfileAgentId.Rows[0][0]);
    //    for (int i = 0; i < myFrndId.Count; i++)
    //    {
    //        BuddyAgentDAL.SetProfileAgentFriendsInfo(agentId, myFrndId[i].ToString());
    //    }


    //}
}